import 'package:flutter/material.dart';

import 'hud.dart';

class HudView extends StatefulWidget {
  const HudView({
    Key? key,
    this.child,
  }) : super(key: key);
  final Widget? child;
  @override
  State<HudView> createState() => _HudViewState();
}

class _HudViewState extends State<HudView> {
  late OverlayEntry _overlayEntry;
  @override
  void initState() {
    _overlayEntry =
        OverlayEntry(builder: (ctx) => Hud.instance.w ?? const SizedBox());
    Hud.instance.oe = _overlayEntry;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Overlay(
        initialEntries: [
          OverlayEntry(
            builder: (BuildContext context) {
              if (widget.child != null) {
                return widget.child!;
              } else {
                return Container();
              }
            },
          ),
          _overlayEntry,
        ],
      ),
    );
  }
}
